package ink.lovejinhu.leetcode;

import java.util.Arrays;

/**
 * @author jinhu
 * created 2021-07-17 18:01
 */
public class Solution_0455 {
    /**
     * 分发饼干
     * 用最小的饼干满足最小需求的孩子
     *
     * @param g
     * @param s
     * @return
     */
    public int findContentChildren(int[] g, int[] s) {
        if (s.length == 0 || g.length == 0) return 0;
        Arrays.sort(g);
        Arrays.sort(s);
        int res = 0;
        for (int i = 0, j = 0; i < g.length && j < s.length; ) {
            if (g[i] <= s[j]) {   //孩子的需求小于饼干的大小
                res++;
                i++;
                j++;
            } else {
                j++;
            }

        }
        return res;
    }

    public static void main(String[] args) {
        Solution_0455 solution_0455 = new Solution_0455();
        int[] g = {1, 2, 3};  //孩子的胃口值
        int[] s = {1, 1};   //饼干的大小
        solution_0455.findContentChildren(g, s);
        System.out.println(solution_0455.findContentChildren(g, s));
    }
}
